<template>
	<section>
		<!--  工具条 -->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;width: 80%;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item>
				<el-date-picker
						v-model="dateValue1"
						type="daterange"
						align="right"
						unlink-panels
						range-separator="  -- 至 --  "
						placeholder="选择开始日期和结束日期"
						:picker-options="pickerOptions"
						style="width: 260px">
				</el-date-picker>
				<el-form-item>
					<el-button type="primary" v-on:click="getListData">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--  列表 -->
		<el-table :data="listData" highlight-current-row v-loading="listLoading" @selection-change="colsChange" style="width: 80%;">
			<el-table-column type="selection" width="50">
			</el-table-column>
			<el-table-column type="index" width="50" fixed>
			</el-table-column>
			<el-table-column prop="customer_id.name" label="客户"  width="120" sortable fixed>
			</el-table-column>
			<el-table-column prop="transUser_id.username" label="移交人员"  width="150" sortable>
			</el-table-column>
			<el-table-column prop="transTime" label="移交时间"  width="150" sortable>
			</el-table-column>
			<el-table-column prop="oldSeller_id.username" label="老市场专员"  width="150" sortable>
			</el-table-column>
			<el-table-column prop="newSeller_id.username" label="新市场专员"  width="150" sortable>
			</el-table-column>
			<el-table-column prop="transReason" label="移交原因" width="200" >
			</el-table-column>
			<el-table-column prop="tenant_id.companyName" label="所属租户" width="150" sortable>
			</el-table-column>
			<el-table-column label="操作" width="100" fixed="right" header-align="center" align="center">
				<template scope="scope">
					<el-button type="danger" size="small" @click="delSubmit(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>

		</el-table>

		<!--  工具条 -->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;width: 80%;">
			<el-button type="danger" @click="batchRemove" :disabled="this.cols.length===0" >批量删除</el-button>
			<el-pagination layout="prev, pager, next" @current-change="showCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
    import util from '../../../common/js/util';
    import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../../api/api';

    export default {
        data() {
            return{
                filters: {
                    name: ''
                },
                listData: [],
                keyword:'',
                pageSize: 10,
                currentPage:1,
                listLoading : false,

                //列表选中的列
                cols: [],

                //日期查询
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                dateValue1: '',




			}
        },
        methods: {
            getListData() {
				let para = {
                    currentPage: this.currentPage,
                    pageSize:this.pageSize,
                    keyword: this.filters.name,
                    date1:this.dateValue1[0],
                    date2:this.dateValue1[1],
                };
                this.listLoading = true;
                this.$http.post('/cusTransfer/findByPage',para).then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.listData = ajaxResult.data.result;
                        this.total = ajaxResult.data.total
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.listLoading = false;
                }).catch(error=>{
                    this.listLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

            //删除
            delSubmit: function (index, row) {
                this.$confirm('确认删除吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    this.$http.delete('/cusTransfer/delete/'+row.id,{}).then(res=>{
                        let ajaxResult =  res.data
                        if (ajaxResult.success){
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.getListData();
                        }else {
                            this.$message({
                                message: '删除失败1',
                                type: 'error'
                            });
                        }
                        this.listLoading = false;
                    }).catch(error=>{
                        this.listLoading = false;
                        this.$message({
                            message: '删除失败2',
                            type: 'error'
                        });
                    })

                });
            },

            //显示当前的页数
            showCurrentChange(val) {
                this.currentPage=val;
                this.getListData();
            },

            colsChange: function (cols) {
                this.cols = cols;
            },

            //批量删除
            batchRemove: function () {
                var ids = this.cols.map(item => item.id)
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = { ids: ids };
                    this.$http.post("/cusTransfer/batchDelete",para).then(res=>{
                        let ajaxResult = res.data;
                        if (ajaxResult.success){
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.getListData();
                        }else {
                            this.$message({
                                message: '删除失败',
                                type: 'error'
                            });
                        }
                        this.listLoading = false;
                    }).catch(error => {
                        this.listLoading = false;
                        this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    })

                })
            },


        },
        mounted() {
            this.getListData();
        }
    }

</script>

<style scoped>

</style>